package org.basis.algorithm.sort;

import org.basis.algorithm.common.SortUtil;

/**
 * 荷兰国旗问题准备
 *
 * @author Mr_wenpan@163.com 2021/12/06 11:36
 */
public class DutchFlagQuestionPre {

    public static void main(String[] args) {
        int[] arr = {1, 30, 22, 90, 20, 77, 33, 55, 66, 8, 5, 9, 3, 0, 10, 7, 2, 3, 9, 8, 2, 2, 5, 1, 2, 4, 5};
        process(arr, 5);
        SortUtil.printArr(arr);
    }

    private static void process(int[] arr, int num) {
        if (arr == null || arr.length < 2) {
            return;
        }
        // 左边界
        int i = 0;
        // 遍历下标
        int index = 0;

        while (index < arr.length) {
            if (arr[index] <= num) {
                SortUtil.swap(index, i, arr);
                i++;
                index++;
            } else {
                // 下标向前走
                index++;
            }
        }

    }
}
